<template>
  <div>
    <el-dialog title="考核信息" :visible.sync="visible" width="950px" top="5vh" append-to-body>
      <el-form ref="assmtForm" :model="formData" size="medium" label-width="100px">
        <el-form-item label="奖励原因" prop="rewardReason">
          <el-input v-model="formData.rewardReason" type="textarea" placeholder="请输入多行文本"
            :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="处罚原因" prop="punishReason">
          <el-input v-model="formData.punishReason" type="textarea" placeholder="请输入多行文本"
            :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="考核分数" prop="score">
          <el-input-number v-model="formData.score" placeholder="计数器"></el-input-number>
        </el-form-item>
        <el-form-item label="考核人姓名" prop="assmtUser">
          <el-input v-model="formData.assmtUser" placeholder="请输入单行文本" clearable :style="{width: '100%'}">
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="handleConfirm">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
    queryAssmt,
    saveAssmtTask
} from "@/api/pms/project/taskAssmt";
export default {
  inheritAttrs: false,
  components: {},
  props: [],
  data() {
    return {
      visible: false,
      formData: {
        rewardReason: undefined,
        punishReason: undefined,
        score: 100,
        assmtUser: undefined,
        taskId: undefined,
      },
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    // 显示弹框
    show(taskId) {
      this.formData.taskId = taskId;
      this.getAssmtData();
      this.visible = true;
    },
    getAssmtData() {
      let queryParams = {};
      queryParams.taskId = this.formData.taskId;
      queryAssmt(queryParams).then(res => {
        this.formData = res.data
      }) 
    },
    close() {
      this.visible = false;
    },
    handleConfirm() {
      if(!this.formData.score) {
        this.$message({
                    type: 'warning',
                    message: '请输入考核分数'
                });
                return
      }
      if(this.formData.score >= 100 && !this.formData.rewardReason) {
        this.$message({
                    type: 'warning',
                    message: '请输入奖励原因'
                });
                return
      }
      if(this.formData.score < 100 && !this.formData.rewardReason) {
        this.$message({
                    type: 'warning',
                    message: '请输入处罚原因'
                });
                return
      }
      saveAssmtTask(this.formData).then(res => {
        console.log("保存返回的内容", res)
        if(res.code == 200) {
          this.$message({
                    type: 'success',
                    message: '保存成功'
                });
          this.visible = false;
        }
      })

    },
  }
}

</script>
<style>
</style>
